import Vue from 'vue'
import VueRouter from 'vue-router'

// import Home from '../components/Home.vue'
const Home = ()=>import(/*webpackChunkName:"login_home_welcome"*/'../components/Home.vue')

// import Login from '../components/Login.vue'
const Login = ()=>import(/*webpackChunkName:"login_home_welcome"*/'../components/Login.vue')
// import Welcome from '../components/Welcome.vue'
const Welcome = ()=>import(/*webpackChunkName:"login_home_welcome"*/'../components/Welcome.vue')

// import Users from '../components/user/Users.vue'
const Users = ()=>import(/*webpackChunkName:"users_roles_rights"*/'../components/user/Users.vue')

// import Rights from '../components/power/Rights.vue'
const Rights = ()=>import(/*webpackChunkName:"users_roles_rights"*/'../components/power/Rights.vue')

// import Roles from '../components/power/Roles.vue'
const Roles = ()=>import(/*webpackChunkName:"users_roles_rights"*/'../components/power/Roles.vue')

// import Cate from '../components/goods/Cate.vue'
const Cate = ()=>import(/*webpackChunkName:"Cate_Params"*/'../components/goods/Cate.vue')

// import Params from '../components/goods/Params.vue'
const Params = ()=>import(/*webpackChunkName:"Cate_Params"*/'../components/goods/Params.vue')

// import GoodsList from '../components/goods/List.vue'
const GoodsList = ()=>import(/*webpackChunkName:"GoodsList_Add"*/'../components/goods/List.vue')

// import Add from '../components/goods/Add.vue'
const Add = ()=>import(/*webpackChunkName:"GoodsList_Add"*/'../components/goods/Add.vue')

// import Order from '../components/order/Order.vue'
const Order = ()=>import(/*webpackChunkName:"Order_report"*/'../components/order/Order.vue')

// import Report from '../components/report/Report.vue'
const Report = ()=>import(/*webpackChunkName:"Order_report"*/'../components/report/Report.vue')

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  }, 
  {
    path: '/Home',
    // name: 'Home', 
    component: Home,
    redirect:'/Welcome',
    children:[{path:'/Welcome',
                name:'Welcome',
                component:Welcome},
                {path:'/Users',component:Users},
                {path:'/Rights',component:Rights},
                {path:'/Roles',component:Roles},
                {path:'/categories',component:Cate},
                {path:'/Params',component:Params},
                {path:'/goods',component:GoodsList},
                {path:'/goods/add',component:Add},
                {path:'/orders',component:Order},
                {path:'/Reports',component:Report},
             ]
  },
  {
    path: '/Login',
    name: 'Login',
    component: Login
  },
]

const router = new VueRouter({
  mode: 'history',
  // base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === "/Login") {
    next();
  } else {
    const token = window.sessionStorage.getItem('token')
    if (!token) {
      next("/Login")
    } else {
      next();
    }
  }
})
export default router